<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>连锁店详情</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
		    <h1 class="mui-title">连锁店详情</h1>
		    
		</header>
			<div class="mui-content fjysq_memcontent" style="background: white; height: 100%;">
				<ul class="fjysq_slis">
					<li class="clearfix">
						<div class="left">店铺名称：</div>
						<input class="right clearfix" type="text" name='chain_name' id='chain_name'>
					</li>
					<li class="clearfix">
						<div class="left">手机号码：</div>
						<input class="right clearfix" type="text" name='chain_mobile' id='chain_mobile'>
					</li>
					<li class="clearfix">
						<div class="left">地址：</div>
						<input class="right clearfix" type="text" name='chain_diz' id='chain_diz'>
					</li>
					<li class="clearfix">
						<div class="left">负责人：</div>
						<input class="right clearfix" type="text" name='chain_user' id='chain_user'>
					</li>
				</ul>
			</div>
		<button type="button" class="fjysq_btn" style="display: none;" id='crete_chain'>保存</button>
		<button type="button" class="fjysq_btn" style="display: none;" id='up_chain'>保存</button>
		<script type="text/javascript" src="../js/jquery.min.js"></script>
		<script type="text/javascript">
			$('.fjysq_memlis > li').bind('click', function(){
			    $(this).addClass('active').siblings().removeClass('active');
			});
		</script>
	</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script>
	$(function(){
		var chain_id = getUrlParam("chain_id");
		if(chain_id !='undefined' && chain_id !=undefined ){
			$.ajax({
				url: APP.api_url + 'agent/chain_info',
				data: {
					token	: get_token(),
					uid		: getUid(),
					chain_id:chain_id
				},
				success: function(data) {
					if(data.code=200){
						var chain_info = data.data;
						$('#chain_name').val(chain_info.name);
						$('#chain_mobile').val(chain_info.mobile);
						$('#chain_diz').val(chain_info.address);
						$('#chain_user').val(chain_info.shopowner);
						$('#up_chain').show();
					}
				}
			});
		}else{
			$('#crete_chain').show();
		}
	})
	
	
	$('#crete_chain').click(function(){
		var chain_name = $("#chain_name").val();
		var chain_mobile = $("#chain_mobile").val();
		var chain_address = $("#chain_diz").val();
		var chain_shopowner = $("#chain_user").val();
		var myreg = /^1[3578]\d{9}$/; 
		if(chain_name == "" || chain_mobile == "" || chain_address == "" || chain_shopowner == "" ){
			layer.msg('请将信息填写完整');
			return false;
		}
		if(!myreg.test(chain_mobile)){
				layer.msg('请输入有效的手机号码！'); 
				return false;
			}
		$.ajax({
				url: APP.api_url + 'agent/create_chain',
				data: {
					token		: get_token(),
					uid			: getUid(),
					name		: chain_name,
					mobile		: chain_mobile,
					address		: chain_address,
					shopowner	: chain_shopowner
				},
				success: function(data) {
						layer.msg(data.msg, {
									time: 1000
							}, function(){
				    			location.href='liansuod_edit.html';
						});
				}
			});
	});
	
	$('#up_chain').click(function(){
		var chain_id = getUrlParam("chain_id");
		var chain_name = $("#chain_name").val();
		var chain_mobile = $("#chain_mobile").val();
		var chain_address = $("#chain_diz").val();
		var chain_shopowner = $("#chain_user").val();
		$.ajax({
				url: APP.api_url + 'agent/up_chain',
				data: {
					token		: get_token(),
					uid			: getUid(),
					name		: chain_name,
					mobile		: chain_mobile,
					address		: chain_address,
					shopowner	: chain_shopowner,
					chain_id	: chain_id
				},
				success: function(data) {
					layer.msg(data.msg, {
									time: 1000
							}, function(){
				    			location.href='liansuod_edit.html';
						});
				}
			});
	});
	
	
</script>